package easyerp.controller;

import easyerp.entity.ProductType;
import easyerp.service.ProductTypeService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/api/producttypes")
public class ProductTypeController {

    private final ProductTypeService producttypeService;

    // 构造函数注入（推荐）
    public ProductTypeController(ProductTypeService producttypeService) {
        this.producttypeService = producttypeService;
    }

    // 查询所有产品
    @GetMapping
    public List<ProductType> getAllProductTypes() {
        return producttypeService.getAllProductTypes();
    }

    // 根据 ID 查询产品
    @GetMapping("/{id}")
    public ProductType getProductTypeById(@PathVariable UUID id) {
        return producttypeService.getProductTypeById(id);
    }

    // 新增产品
    @PostMapping
    public ProductType insertProductType(@RequestBody ProductType productType) {
        return producttypeService.insertProductType(productType);
    }

    // 根据 ID 更新产品
    @PutMapping("/{id}")
    public ProductType updateProductType(@PathVariable UUID id, @RequestBody ProductType productType) {
        return producttypeService.updateProductType(id, productType);
    }

    // 根据 ID 删除产品
    @DeleteMapping("/{id}")
    public void deleteProductType(@PathVariable UUID id) {
        producttypeService.deleteProductType(id);
    }
}
